<?php

/**
 * 定义：为创建一组相关或相互依赖的对象提供一个接口，而且无须指定它们的具体类。
 * 例子：获取用户订单金额
 */
abstract class AbstractFactoryUserOrder
{
    public abstract function GetOrder();
    public abstract function GetUser();
    public function Query(){
        return $this->GetUser()->name()."的订单费用:".$this->GetOrder()->amount()."\n";
    }

}
class  FactoryCommonUserZhiFuOrder extends AbstractFactoryUserOrder{
    public function GetOrder(){
        return new ZhiFuOrder();
    }
    public function GetUser(){
        return new CommonUser();
    }

}
class  FactoryVipUserFeiZhiFuOrder extends AbstractFactoryUserOrder{
    public function GetOrder(){
        return new FeiZhiFuOrder();
    }
    public function GetUser(){
        return new VipUser();
    }

}
interface  Order{
    public function amount();
}
class ZhiFuOrder implements Order{

    public function amount(){
        return 10;
    }
}
class FeiZhiFuOrder implements Order{
   
    public function amount(){
        return 20;
    }
}

interface User{
    public function name();
}
class CommonUser implements User{
    public function name(){
        return "张三";
    }
}
class VipUser implements User{
    public function name(){
        return "李四";
    }
}

function main(AbstractFactoryUserOrder $userOrder){
    echo $userOrder->GetUser()->name()."\n";
    echo $userOrder->GetOrder()->amount()."\n";
    echo $userOrder->Query()."\n";
}

main(new FactoryCommonUserZhiFuOrder());

//main(new FactoryVipUserFeiZhiFuOrder());
